package com.gwq.computed;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Exercise2 {

    private static final short OPERATION_NUMBER=50;
    private static final short COLUMN_NUMBER=5;

    private List<BinaryOperation2> operationList = new ArrayList<>();
    private int current=0;


    public void add(BinaryOperation2 binaryOperation2){
        this.operationList.add(binaryOperation2);
    }


    //从算式基随机产生数据




    //随机算式
    public void generateBinaryExercise( int operationCount){
        BinaryOperation2 anOperation;
        while(operationCount>0){
            do{
                anOperation = generateOperation();
            }while (operationList.contains(anOperation));
            operationList.add(anOperation);
            operationCount--;
        }
    }

    private BinaryOperation2 generateOperation(){
        Random random = new Random();
        int opValue = random.nextInt(2);
        if(opValue==1){
            return new AdditionOperation();
        }
        return new SubstractOperation();
    }


    //加法算式
    public void generateAdditionExercise(int operationCount){
        BinaryOperation2 anOperation;
        while(operationCount>0){
            do{
                anOperation = new AdditionOperation();
            }while (operationList.contains(anOperation));
            operationList.add(anOperation);
            operationCount--;
        }
    }


    //减法算式
    public void GenerateSubstractExercise(int operationCount){
        BinaryOperation2 anOperation;
        while(operationCount>0){
            do{
                anOperation = new SubstractOperation();
            }while (operationList.contains(anOperation));
            operationList.add(anOperation);
            operationCount--;
        }
    }


    //下面两个方法用于实现遍历数据
    public boolean hasNext(){
        return current <= operationList.size()-1;
    }

    public BinaryOperation2 next(){
        return operationList.get(current++);
    }


    public boolean contains(BinaryOperation2 anOperation,int length){
        boolean found = false;
        if(operationList.contains(anOperation)){
            found = true;
        }
        return found;
    }


}
